package com.qingzhu.dao.impl;

import com.qingzhu.dao.SpecificationOptionDao;
import com.qingzhu.pojo.SpecificationOption;
import com.qingzhu.util.CreateSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class SpecificationOptionDaoImpl implements SpecificationOptionDao {

    @Override
    public SpecificationOption findById(int id) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            SpecificationOptionDao specificationOptionDao = sqlSession.getMapper(SpecificationOptionDao.class);
            return specificationOptionDao.findById(id);
        }
    }

    @Override
    public List<SpecificationOption> findBySpecificationId(int specId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            SpecificationOptionDao specificationOptionDao = sqlSession.getMapper(SpecificationOptionDao.class);
            return specificationOptionDao.findBySpecificationId(specId);
        }
    }

    @Override
    public SpecificationOption findIdFromName(String optionName, int specId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            SpecificationOptionDao specificationOptionDao = sqlSession.getMapper(SpecificationOptionDao.class);
            SpecificationOption idFromName = specificationOptionDao.findIdFromName(optionName, specId);
            return idFromName;
        }
    }
}
